import * as React from 'react'
import {compose} from 'recompose'
import {curry} from 'ramda'
import {MutationComponent} from '../util/index'

export default curry(({gql, options = {}, propName}, ComposedComponent: React.Component) => {

    class Mutate extends React.Component {
        render() {
            const thisOptions = typeof options == 'function' ? options(this.props) : options
            return (
                <div>
                    <MutationComponent gql={gql}
                                       options={thisOptions}
                                       render={mutate => (
                                           <ComposedComponent {...this.props} {...{[propName]: mutate}}/>
                                       )}
                    />
                </div>
            )
        }
    }

    return Mutate
})